function creatRequest (url,method,data) {
    var header = ''
    var AMAP = 'https://miniapp.odeman.com/summercamp'
  
    return new Promise((resolve,reject)=>{
        if (method.toUpperCase()=='POST') {
       
            header ={ "Content-Type":"application/x-www-form-urlencoded"}
        } else {
            header = {"content-type": "application/json"}
        }
        wx.showLoading({ title: '加载中' })
        console.log(AMAP + url)
        wx.request({
            url: AMAP + url,
            data: data || {},
            header,
            method:method,
            success: function(res) {
                wx.hideLoading()
              console.log(res.data)
              if (res.data.status == 'success') {
                  resolve(res.data)
              } else {
                  reject(new Error(res.data))
              }
            },
            fail:function(err) {
                wx.hideLoading()
                wx.showToast({
                    title: '网络异常，请稍后再试',
                    icon: 'none'
                  })
                  reject(new Error(res))
            }
          })
    })
}
function CityList (opt) {
    return creatRequest ('/index_city.php','get',opt)
}
function getPhone(opt) {
    return creatRequest('/get_area_phone.php','get',opt)
}

function login (opt) {
    return creatRequest('/login.php','post',opt)
}
module.exports = {
    CityList:CityList,
    getPhone:getPhone,
    login:login
}